function fire_ajax_submit() {
    //Get form
    var form  = $('#fileUploadForm')[0];
    var data = new FormData(form);
    data.append("CustomField","This is some extra data,testing");
    $("#btnSubmit").prop("disabled",true);
    $.ajax({
        type: "POST",
        enctype: "multipart/form-data",
        url: "/api/upload/multi",
        data: data,
        processData: false,
        contentType: false,
        cache: false,
        timeout: 600000,
        success: function (data) {
            $("#result").text(data);
            $("#btnSubmit").prop("disabled",false);
        },
        error: function (e){
            $('#result').text(e.responseText);
            $("#btnSubmit").prop("disabled",false);
        }
    });

}



$(document).ready(function(){
    $("#btnSubmit").click(function (event) {
        //stop submit the form,we will post it manually.
        event.preventDefault();
        fire_ajax_submit();
    });

    $("#search-form").submit(function (event) {
        event.preventDefault();
        fire_ajax();
    })
});


function fire_ajax() {
    var search = {};
    search["username"] = $("#username").val();
    $("btn-search").prop("disabled",false);
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "/api/search",
        data: JSON.stringify(search),
        data_type: 'json',
        cache: false,
        timeout: 600000,
        success: function (data) {
            var json = "<h4>Ajax Response</h4><pre>"+JSON.stringify(data,null,4) + "</pre>";
            $("#feedback").html(json);
            $("#btn-search").prop("disabled",false);
        },
        error: function (e) {
            var json = "<h4>Ajax Response</h4><pre>"+e.responseText + "</pre>";
            $("#feedback").html(json);
            $("#btn-search").prop("disabled",false);
        }
    });
}

